﻿using System;
using Sunny.UI;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ClassLibrary;
using Forms.UserController;
namespace Forms
{
    public partial class MyOrder : UIForm
    {
        User user = new User();
        OrderService orderService = new OrderService();
        public MyOrder(User user)
        {
            InitializeComponent();
            this.user = user;
            InitPerInfomation();
            List<Order> orders = orderService.GetOrderByUserID(user.UserID);
            ListMyOrder(orders);
            Color userColor = MainForm.MainForm.userColor;
            UIStyles.InitColorful(userColor, Color.White);
        }
        private void InitPerInfomation()//初始化个人信息
        {
            UserName.Text = user.UserName;
            StudentID.Text = user.UserID;
            Telephone.Text = user.UserTele;
            ID.Text = user.UserIdentityCard;
            Address.Text = user.UserAddress;
        }
        private void ListMyOrder(List<Order> orders)
        {
            panel.Controls.Clear();
            panel.AutoScroll = true; // 启用自动滚动条
            int boxHeight = 220;
            int i = 0;
            foreach (Order order in orders)//对于每个商品有一个商品框
            {
                Orderbox box = new Orderbox(order);
                box.Top = i * boxHeight; // 设置用户控件的位置
                i++;
                panel.Controls.Add(box); // 将用户控件添加到 Panel 中
            }
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void TimeBtn_Click(object sender, EventArgs e)
        {
            List<Order> orders = new List<Order>();
            orders = orderService.GetOrderByUserIDandTime(user.UserID);
            ListMyOrder(orders);
        }

        private void SumBtn_Click(object sender, EventArgs e)
        {
            List<Order> orders = new List<Order>();
            orders = orderService.GetOrderByUserIDandSum(user.UserID);
            ListMyOrder(orders);
        }
    }
}
